package FileIO.stream;

import FileIO.Student;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;



public class useDataOutputStream {
    public static void main(String[] args) throws IOException {
        List<Student> studentList = Arrays.asList(new Student[] {
                new Student("张三", 18, 80.9d),
                new Student("王五", 20, 67.5d)
        });
        DataOutputStream output = new DataOutputStream((new FileOutputStream("src/main/data/students.dat")));
        try {
            output.writeInt(studentList.size());
            for (Student s : studentList) {
                output.writeUTF(s.getName());
                output.writeInt(s.getAge());
                output.writeDouble(s.getScore());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            output.close();
        }
    }
}
